package com.ruoyi.web.controller.community.integral;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.integral.IntUserStatistic;
import com.ruoyi.community.service.integral.IIntUserStatisticService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户积分信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-08
 */
@RestController
@RequestMapping("/integral/statistic")
public class IntUserStatisticController extends BaseController
{
    @Autowired
    private IIntUserStatisticService intUserStatisticService;

    /**
     * 查询用户积分信息列表
     */
    @PreAuthorize("@ss.hasPermi('integral:statistic:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntUserStatistic intUserStatistic)
    {
        startPage();
        List<IntUserStatistic> list = intUserStatisticService.selectIntUserStatisticList(intUserStatistic);
        return getDataTable(list);
    }


    /**
     * 导出用户积分信息列表
     */
    @PreAuthorize("@ss.hasPermi('integral:statistic:export')")
    @Log(title = "用户积分信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IntUserStatistic intUserStatistic)
    {
        List<IntUserStatistic> list = intUserStatisticService.selectIntUserStatisticList(intUserStatistic);
        ExcelUtil<IntUserStatistic> util = new ExcelUtil<IntUserStatistic>(IntUserStatistic.class);
        return util.exportExcel(list, "用户积分信息数据");
    }

    /**
     * 获取当前登录用户信息
     */
    @GetMapping(value = "/info")
    public AjaxResult getInfo()
    {
        IntUserStatistic params = new IntUserStatistic();
        params.setUserId(SecurityUtils.getUserID());
        params.setCommunityId(SecurityUtils.getCommunityId());
        IntUserStatistic info = intUserStatisticService.getUserInfo(params);
        return AjaxResult.success(info);
    }

    /**
     * 获取用户积分信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('integral:statistic:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(intUserStatisticService.selectIntUserStatisticById(userId, SecurityUtils.getCommunityId()));
    }

    /**
     * 新增用户积分信息
     */
    @PreAuthorize("@ss.hasPermi('integral:statistic:add')")
    @Log(title = "用户积分信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntUserStatistic intUserStatistic)
    {
        return toAjax(intUserStatisticService.insertIntUserStatistic(intUserStatistic.getUserId(),intUserStatistic.getCommunityId()));
    }

    /**
     * 修改用户积分信息
     */
    @PreAuthorize("@ss.hasPermi('integral:statistic:edit')")
    @Log(title = "用户积分信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntUserStatistic intUserStatistic)
    {
        return toAjax(intUserStatisticService.updateIntUserStatistic(intUserStatistic));
    }

    /**
     * 删除用户积分信息
     */
    @PreAuthorize("@ss.hasPermi('integral:statistic:remove')")
    @Log(title = "用户积分信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(intUserStatisticService.deleteIntUserStatisticByIds(userIds));
    }
}
